package com.gitee.shoes.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.shoes.dao.ProductSoldRecordMapper;
import com.gitee.shoes.entity.ProductSoldRecord;
import com.gitee.shoes.service.IProductSoldRecordService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LYH
 * @since 2020-12-13
 */
@Service
public class ProductSoldRecordServiceImpl extends ServiceImpl<ProductSoldRecordMapper, ProductSoldRecord> implements IProductSoldRecordService {

    @Override
    public List<ProductSoldRecord> findAllByProductIdAndOrderByTimeDescAndLimit(Long productId, int limit) {
        return list(Wrappers.<ProductSoldRecord>lambdaQuery().eq(ProductSoldRecord::getProductId, productId)
                .orderByDesc(ProductSoldRecord::getTransTime).orderByAsc(ProductSoldRecord::getId).last("limit " + limit));
    }
}
